package com.cloudkinto.controller.finance;


import com.cloudkinto.base.BaseController;
import com.cloudkinto.common.annotations.UserSessionRequired;
import com.cloudkinto.common.web.PageResult;
import com.cloudkinto.common.web.SingleResult;
import com.cloudkinto.service.finance.CostRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author ding
 * @since 2020-06-10
 */
@RestController
@Api(tags = "财务-支出记录对外抛出api模块")
@RequestMapping("/api/open/cost")
public class CostRecordOpenApiController extends BaseController {
    private final Logger logger = LoggerFactory.getLogger(CostRecordOpenApiController.class);

    @Autowired
    private CostRecordService service;

    @UserSessionRequired
    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查看详情", notes = "根据id查看详情")
    public SingleResult detail(@PathVariable("id") Long id) {
        return SingleResult.success("查询成功", service.detail(id));
    }

    @UserSessionRequired
    @GetMapping("/pageInit")
    @ApiOperation(value = "查询初始化", notes = "查询初始化")
    public SingleResult pageInit() {
        return service.pageInit();
    }


    @UserSessionRequired
    @GetMapping("/listPage")
    @ApiOperation(value = "查询（分页）", notes = "查询（分页）")
    public PageResult listPage(String dateStart, String dateEnd, String type, String current, String pageSize, String keyword) {
        Long companyId = getCompanyId();
        Map<String, String> map = new HashMap<>();
        map.put("dateStart", dateStart);
        map.put("dateEnd", dateEnd);
        map.put("current", current);
        if (getShopId() != null) {
            map.put("shopId", getShopId() + "");
        }
        map.put("pageSize", pageSize);
        map.put("type", type);
        map.put("companyId", companyId + "");
        map.put("keyword", keyword);
        return service.getListPage(map);
    }


}

